package com.apes.fn.fico.reimbursement.model;

import com.apes.fico.masterdata.gl.model.AccountingChart;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 费用报销单类型明细表
 * Created by lishikun on 2021/1/27 10:52
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ReimbursementTypeItem.CONST_TABLE_NAME)
public class ReimbursementTypeItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_reimbursement_type_item";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "费用报销单类型明细表", padding = 8)
    @Comment("费用报销单类型明细编码")
    private String id;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fee_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private FeeType feeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cost_center_id", referencedColumnName = "id")
    @Comment("报销部门")
    private DutyCenter dutyCenter;  //报销部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("税率")
    private Tax tax;

    @Comment("报销金额")
    @Column(name = "reimbursement_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double reimbursementAmount = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reimbursement_item_id", referencedColumnName = "id")
    @Comment("费用报销单")
    private ReimbursementItem reimbursementItem;

    // TODO 进项税
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "input_tax_id", referencedColumnName = "id")
    @Comment("进项税")
    private Tax inputTax;

    @Name
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "accountingt_chart_id", referencedColumnName = "id")
    @Comment("会计科目")
    private AccountingChart accountingChart;

    @Comment("备注")
    @Column(name = "remark_one", length = 120)
    private String remarkOne;

    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("发票类型")
    @JoinColumn(name = "invoice", referencedColumnName = "id")
    private Enumeration invoice; //发票类型

    @Comment("发票号码")
    @Column(name = "invoice_number", length = 120)
    private String invoiceNumber;

    @Comment("价税合计金额")
    @Column(name = "price_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double priceTax = 0;

    @Comment("进项税金")
    @Column(name = "input_tax_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double inputTaxAmount = 0;

    @Comment("原因")
    @Column(name = "reason", length = 120)
    private String reason;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "xmh", referencedColumnName = "id")
    private Enumeration xmh;

}
